package mygame;

import com.jme3.app.SimpleApplication;
import com.jme3.bullet.BulletAppState;
import com.jme3.bullet.collision.shapes.BoxCollisionShape;
import com.jme3.bullet.control.GhostControl;
import com.jme3.bullet.control.RigidBodyControl;
import com.jme3.bullet.objects.PhysicsRigidBody;
import com.jme3.light.AmbientLight;
import com.jme3.light.DirectionalLight;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.renderer.RenderManager;
import com.jme3.renderer.queue.RenderQueue;
import com.jme3.scene.Geometry;
import com.jme3.scene.Spatial;
import com.jme3.scene.shape.Box;
import com.jme3.util.SkyFactory;

/**
 * test
 * @author normenhansen
 */
public class Main extends SimpleApplication {
    
    private BulletAppState bulletAppState;
    private BasicTower test;
    
    public static void main(String[] args) {
        Main app = new Main();
        app.start();
    }

    @Override
    public void simpleInitApp() {
        
        bulletAppState = new BulletAppState();
        
        stateManager.attach(bulletAppState);
        bulletAppState.getPhysicsSpace().enableDebug(assetManager);
        bulletAppState.getPhysicsSpace().setGravity(new Vector3f(0f,0f,0f));
        

        //flyCam.setEnabled(false);
        
        //Spatial tower = assetManager.loadModel("Models/veza/tower.j3o");
        //GhostControl ghost = new GhostControl(
            
        /*RigidBodyControl ghost = new RigidBodyControl(new BoxCollisionShape(new Vector3f(1,1,1)));  // a box-shaped ghost
        tower.addControl(ghost);    
        bulletAppState.getPhysicsSpace().add(ghost);
        rootNode.attachChild(tower);
        tower.setLocalTranslation(3f, 3f, 0);
         tower.scale(0.1f, 0.1f, 0.1f);
         */
        //BasicTower towerCreated2 = new BasicTower(new Vector3f(2.0f,2.0f, 2.0f), 1f, this);
         /*
          Spatial tower1 = assetManager.loadModel("Models/veza/tower.j3o");
          tower1.setLocalTranslation(2, 0, 2);
         tower1.scale(0.05f, 0.05f, 0.05f);
        rootNode.attachChild(tower1);
        */
       // BoxCollisionShape boxShape = new BoxCollisionShape();
            //RigidBodyControl myPhys = new RigidBodyControl(boxShape, 0.0f);
            //tower1.addControl(myPhys);
        BasicTower towerCreated = new BasicTower(new Vector3f(1.0f,1.0f, 1.0f), 0.1f, this);
        Minion newMinion = new Minion (0.05f, new Vector3f(10f,1.0f,3f), this);
        
        Arrow arrow = new Arrow(newMinion.getMinion(), this);
        
        test = towerCreated;
        //rootNode.attachChild(towerCreated.tower2);
        //towerCreated.shoot(myPhys);
        /* 
        DirectionalLight sun = new DirectionalLight();
        sun.setDirection(new Vector3f(0.2f, -0.2f, 0.2f).normalizeLocal());
        sun.setColor(ColorRGBA.White);
        rootNode.addLight(sun);
       */ 
        //System.out.println("Vypis1 " + towerCreated.tower2.getControl(GhostControl.class).getOverlappingObjects());
        //System.out.println("Vypis2 " + towerCreated.tower2.getControl(GhostControl.class).getOverlappingCount());
        

       
                Vector3f sunDirection = new Vector3f(0.2f, -0.2f, 0.2f).normalizeLocal();
        
        DirectionalLight sun = new DirectionalLight();
    sun.setDirection(sunDirection);
    
    sun.setColor(ColorRGBA.White);
    rootNode.addLight(sun); 
    
    AmbientLight al = new AmbientLight();
al.setColor(ColorRGBA.White.mult(1.3f));
rootNode.addLight(al);
     /*
    Spatial treeNode = assetManager.loadModel("Models/veza/tower.j3o");
    treeNode.setShadowMode(RenderQueue.ShadowMode.Cast);
        treeNode.setLocalTranslation(0,0, 0);
        treeNode.setLocalScale(0.1f);

        rootNode.attachChild(treeNode);
    */
    flyCam.setMoveSpeed(5);
    
    }

    @Override
    public void simpleUpdate(float tpf) {
        //TODO: add update code
        //System.out.println("Vypis1 " + test.tower2.getControl(GhostControl.class).getOverlappingObjects());
        //System.out.println("Vypis2 " + test.tower2.getControl(GhostControl.class).getOverlappingCount());
        //test.update(tpf);
    }

    @Override
    public void simpleRender(RenderManager rm) {
        //TODO: add render code
    }
}
